<template>
    <div>
        {{id}}
        <br>
        {{list}}<br>
        {{value}}<br>
        {{workllist}}
        
            <div v-for="(j,pindex) in list">
                <van-field :label="i.label+index" v-for="(i,index) in j" v-model="value[pindex+i.key]"></van-field>
            
            
            </div>
            
            <van-button @click="add">+</van-button>
            <van-button @click="save" >提交</van-button>
            <br>    
            <br> 
            <br> 
            <br>
            {{wlist}}
            <div v-show="a">
                <div v-for="i in workllist" >
                    <van-field :label="i.name" v-model="wlist[i.name]" v-if="i.type == 'input'"></van-field>
                    <van-field :label="i.name" v-model="wlist[i.name]" v-else-if="i.type == 'textarse'"></van-field>
                
                    <!-- <van-radio-group v-else-if="i.type == 'redi'">
                        <van-radio name="1" label-disabled>单选框 1</van-radio>
                        <van-radio name="2" label-disabled>单选框 2</van-radio>
                    </van-radio-group>
                    <div v-else-if="i.type == 'checkbo'">
                        <van-checkbox>sdasdasd</van-checkbox>
                    </div> -->
                    
                </div>
                <van-button @click="newadd" >提交</van-button>
            </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                list:[[{'label':'名称','key':'name'},{'label':'类型','key':'type'},{'label':'字段名','key':'field'},{'label':'值','key':'value'}]],
                number:1,
                value:{},
                id:this.$route.query.id,
                a:0,
                workllist:[],
                wlist:{}
            }
        },
        methods: {
        //
        add(){
            this.list.push([{'label':'名称','key':'name'},{'label':'类型','key':'type'},{'label':'字段名','key':'field'},{'label':'值','key':'value'}])
            this.number +=1
            
        },
        //
        save(){
            var l=[]
            for(var i=0;i<this.number;i++){
                
                var name = i+'name' 
                var type =  i+'type'
                var value =  i+'value'
                var field =  i+'field'
                var dict = {'name':this.value[name],'value':this.value[value],'type':this.value[type],'field':this.value[field]}
                l.push(dict)
            }
            
            this.$axios.post('/work/addwork/',{'params':JSON.stringify(l),'id':this.id}).then(res=>{
                    this.a = 1
            })
            
        },
        getworkl(){
                this.$axios.get('/work/add/?id='+this.id).then(res=>{
                    this.workllist = JSON.parse(res.data.list)
                
                })
            },
        //添加到新表中的数据
        newadd(){

            console.log(this.wlist)
            this.$axios.post('/work/record/',{'params':JSON.stringify(this.wlist),'wid':this.id}).then(res=>{

            })
        }
        },
        mounted() {
            this.getworkl()
        },
    }
</script>

<style scoped>

</style>